import { Course } from "@/api/interface/index";
import { CHAPTER, COURSE } from "@/api/config/servicePort";
import http from "@/api";

/**
 * @name 课程模块
 */

export const getCourseInfoApi = (course_id: any) => {
  return http.get<Course.ResCourseInfo>(COURSE + `/` + course_id + `/info`);
};

export const getChapterMenuApi = (course_id: number) => {
  return http.get<Course.ResChapterMenu[]>(COURSE + `/` + course_id + `/chapter/menus`);
};

export const getCourseListApi = (condition: any) => {
  return http.post<any[]>(COURSE + `/list`, { condition: condition });
};

export const getCourseTreeListApi = (condition: any) => {
  return http.post<any[]>(COURSE + `/treelist`, { condition: condition });
};

export const addCourseApi = async (params: any) => {
  return http.post(COURSE + `/add`, params);
};

export const updateCourseApi = async (params: any) => {
  return http.post(COURSE + `/update`, params);
};

export const deleteCourseApi = async (params: any) => {
  return http.post(COURSE + `/delete`, params);
};

export const sortCourseApi = async (params: { data: { [p: number]: number }; course_id: number }) => {
  return http.post(COURSE + `/sort`, params);
};
